package com.shrct.businessprocess.customerservice.impl;

import com.shrct.businessprocess.customerservice.RCServiceImportService;
import com.shrct.businessprocess.organization.RCSupplier;
import com.shrct.businessprocess.product.RCDerivedFullServiceProductSpecification;
import com.shrct.businessprocess.product.RCFullServiceProductEntry;
import com.shrct.businessprocess.product.RCIdentifiablePhysicalProductEntry;
import com.shrct.businessprocess.product.RCLogicProduct;
import com.shrct.businessprocess.product.RCProductSpecification;
import com.shrct.businessprocess.product.RCProductSpecificationDAO;
import com.shrct.businessprocess.product.RCServiceLevel;
import com.shrct.businessprocess.product.RCServiceResponseTime;
import edu.fudan.mylang.pf.BaseService;
import edu.fudan.mylang.utils.DateUtil;
import java.util.Date;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("com.shrct.businessprocess.customerservice.RCServiceImportService")
public class RCServiceImportServiceImpl extends BaseService implements RCServiceImportService {
  @Autowired
  private RCProductSpecificationDAO productSpecificationDAO;
  
  public void importProductService(final String name, final String projectid, final String serviceSpec, final String serviceContractCode, final RCSupplier productSupplier, final RCIdentifiablePhysicalProductEntry product, final RCServiceLevel serviceLevel, final RCServiceResponseTime serviceResponseTime, final Date startDate, final Date dueDate) {
    Double _betweenMonth = DateUtil.betweenMonth(dueDate, startDate);
    double _plus = ((_betweenMonth).doubleValue() + 0.5);
    final int months = Double.valueOf(_plus).intValue();
    RCProductSpecification _type = product.getType();
    final RCDerivedFullServiceProductSpecification s = this.productSpecificationDAO.getFullService(_type, serviceSpec, serviceLevel, serviceResponseTime, Integer.valueOf(months));
    RCLogicProduct _logicProduct = product.getLogicProduct();
    RCFullServiceProductEntry _registerFullServiceProduct = _logicProduct.registerFullServiceProduct(name, projectid, serviceContractCode, s, startDate, dueDate);
    final Procedure1<RCFullServiceProductEntry> _function = new Procedure1<RCFullServiceProductEntry>() {
        public void apply(final RCFullServiceProductEntry it) {
          it.setSupplier(productSupplier);
        }
      };
    ObjectExtensions.<RCFullServiceProductEntry>operator_doubleArrow(_registerFullServiceProduct, _function);
  }
}
